package org.wisdom.data.jpa;

import com.alibaba.druid.filter.config.ConfigTools;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author 张智研
 * @date 2022/05/13 16:12
 **/
public class StringBeta {

    public static void main(String[] args) {
        String exp = "\\{(.*?)}";
        String value = "This {is} a samle {string} that {contains} {substrings} inside curly {braces}";
        Pattern pattern = Pattern.compile(exp);
        Matcher matcher = pattern.matcher(value);
        List<String> matches = new ArrayList<>();
        while (matcher.find()) {
            String group = matcher.group();
            matches.add(group);
        }
        String[] groups = matches.toArray(new String[0]);
        System.out.println(Arrays.toString(groups));
        for (String str : groups) {
            value = value.replace(str, "xx");
            System.out.println(value);
        }

        String a = "{xxxxxx}";
        int oldLength = a.length();
        String b = a.replace("x", "");
        int newLength = b.length();
        System.out.println(a);
        System.out.println(oldLength);
        System.out.println(b);
        System.out.println(newLength);
        System.out.println(oldLength - newLength);

        DecimalFormat decimalFormat = new DecimalFormat("000000");
        System.out.println(decimalFormat.format(1));

        int n = 8;
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < n; i++) {
            stringBuilder.append("0");
        }
        decimalFormat = new DecimalFormat(stringBuilder.toString());
        System.out.println(decimalFormat.format(1));
        System.out.println(decimalFormat.format(10));
        System.out.println(decimalFormat.format(100));
        System.out.println(decimalFormat.format(1000));

        System.out.println("asd{123}{y}{e}{x}df".replaceAll("[{}]", ""));

        try {
            String[] a1 = ConfigTools.genKeyPair(1024);
            System.out.println("私钥：" + a1[0]);
            System.out.println("公钥：" + a1[1]);
            String[] params = new String[1];
            params[0] = "123456";
            String b1 = ConfigTools.encrypt(a1[0], "123456");
            System.out.println("加密后的密码：" + b1);
            String b2 = ConfigTools.decrypt(a1[1], b1);
            System.out.println("解密后的密码：" + b2);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
